#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct hash_table
{
char ui[20];
char pw[20];
int qq;
} obj[30];

int hashfunc1();
int hashfunc2();
int hashfunc3();

void main()
{
int i,j,a,x;
char userid[20],password[20];
i=j=a=0;
FILE *fs;
fs=fopen("db.txt","r");
int count =0;
int choice;
printf("::HASH FUNCTIONS ::\nHash function '1' [Ascii] \nHash Function '2' [Length] \nHash Function '3' [Vowels]\n");
printf("Enter your choice : ");
scanf("%d",&choice);

for(i=0;i<30;i++)
	{
	obj[i].qq=0;		
	}

for(i=0;i<30;i++)
{
if (choice==1)
{
	x=hashfunc1();
}
if (choice==2)
{
	x=hashfunc2();
}
if (choice==3)
{
	x=hashfunc3();
}

	fflush(stdin);
	count=0;

	do
	{
		if(obj[x].qq==0)
		{
			obj[x].qq=1;	
			fscanf(fs,"%s",obj[x].ui);
			fscanf(fs,"%s",obj[x].pw);
			break;
		}
		else 
		{ 
			x=(x+1)%30;
			count=count+1;
		}	
	} while(count!=30);
}

for(i=0;i<30;i++)
	{
		printf("\n");
		printf("Userid is %s \n",obj[i].ui);
		printf("Pwd is %s \n",obj[i].pw);
	}
char ch;
int flag=0,flag2=0;
do
{
printf("Enter user-id\n");
scanf("%s",userid);
for(j=1;j<4;j++)
{
printf("Enter password(trial %d)\n",j);
scanf("%s",password);
i=0;
int b=0;
if(choice==1)
{
	while(userid[i]!='\0')
	{
	b=b+userid[i];
	i++;
	}
b=b%30;
}
i=0;
if(choice==2)
{
	while(userid[i]!='\0')
	{
	b=b+1;
	i++;
	}
b=b%30;
}


if(choice==3)
{	
	while(userid[i]!='\0')
	{
	if(userid[i]=='a' || userid[i]=='e' || userid[i]=='i' || userid[i]=='o' || userid[i]=='u')
	{b=b+1;}
	i++;
	}
b=b%30;
}



for(i=0;i<30;i++)
{
	if(strcmp(obj[b].ui,userid)==0)
	{
		flag=1;
		if(strcmp(obj[b].pw,password)==0)
			{printf("Password matched\n");
			flag2=1;}
		else
			printf("Password does not match\n");
		break;
	}
	b=(b+1)%30;
}
if(flag2==1)
{break;}
}
if(flag==0)
{printf("Userid not found\n");}

printf("Do you want to enter more user-ids? ");
scanf("%s",&ch);
} while(ch=='y' || ch=='Y');
}


int hashfunc1()
{
int a=0,x;
char c;
FILE *fa;
fa=fopen("db.txt","r");
while((c=fgetc(fa))!=' ')
	{ 
		a=a+c; 
	}
	printf("Ascii = %d",a);
	x=a%30;
return x;
}

int hashfunc2()
{
int a=0,x;
char c;
FILE *fa;
fa=fopen("db.txt","r");
while((c=fgetc(fa))!=' ')
	{ 
		a=a+1; 
	}
	printf("Length = %d",a);
	x=a%30;
return x;

}

int hashfunc3()
{
int a=0,x;
char c;
FILE *fa;
fa=fopen("db.txt","r");
while((c=fgetc(fa))!=' ')
	{ 
		if(c=='a' || c=='e' || c=='o' || c=='i' || c=='u')
		{a=a+1;} 
	}
	printf("Length = %d",a);
	x=a%30;
return x;
}


